package si.cir.util;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import si.cir.entities.Stuk;

public class StukHandler extends DefaultHandler{
	
	private List<Stuk> dogodki = new ArrayList<Stuk>();
	private Stuk dogodek;
	private String currentElement = "";
	
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		if(qName.equals("dogodek")){
			currentElement = qName;
			dogodek = new Stuk();
			dogodek.setPovezava(attributes.getValue("povezava"));
		}
	}
	
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		if(qName.equals("dogodek")){
			dogodki.add(dogodek);
			currentElement = "";
		}
	}
	
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		if(currentElement.equals("dogodek"))
			dogodek.setIme(new String(ch, start, length));
	}
	
	public List<Stuk> getNovice(){
		return dogodki;
	}
}
